﻿<EditDataFormTemplateSpec 
	xmlns="bb_appfx_editdataformtemplate"
	xmlns:common="bb_appfx_commontypes" 
	ID="cf81db36-577f-4b75-83bc-e112e477c190" 
	Name="Revenue Edit Data Form Custom"
	Description="Revenue Edit Form - Custom" 
	Author="Blackbaud Professional Services"
	DataFormInstanceID="349f23df-b12c-43d4-96c1-60d7b6b80575" 
	RecordType="Revenue"
	common:SecurityUIFolder="Service Bus Adapter"
	>

	<SPDataForm>

		<!-- define the edit load SP, which is used to load the data for the form -->
		<LoadImplementation SPName="USP_DATAFORMTEMPLATE_EDITLOAD_REVENUE_CUSTOM">
			<common:CreateProcedureSQL> 
				<![CDATA[
create procedure dbo.USP_DATAFORMTEMPLATE_EDITLOAD_REVENUE_CUSTOM(
  @ID uniqueidentifier,
  @DATALOADED bit = 0 output,
  @TSLONG bigint = 0 output,
  @Amount money = null output,
  @Description nvarchar(255) = null output,
  @Designation nvarchar(255) = null output,
  @SubDesignation nvarchar(255) = null output
)
as

	set nocount on;

	-- be sure to set these, in case the select returns no rows
	set @DATALOADED = 0
	set @TSLONG = 0

	-- populate the output parameters, which correspond to fields on the form.  Note that
	-- we set @DATALOADED = 1 to indicate that the load was successful.  Otherwise, the system
	-- will display a "no data loaded" message.  Also note that we fetch the TSLONG so that concurrency
	-- can be considered.
	select
		@DATALOADED = 1,
		@TSLONG = TSLONG	from dbo.REVENUE
	where ID = @ID

	return 0;
				]]>
			</common:CreateProcedureSQL>
		</LoadImplementation>

		<SaveImplementation SPName="USP_DATAFORMTEMPLATE_EDIT_REVENUE_CUSTOM">
			<common:CreateProcedureSQL>
				<![CDATA[
create procedure dbo.USP_DATAFORMTEMPLATE_EDIT_REVENUE_CUSTOM (
@ID uniqueidentifier,
@Amount money,
@Description nvarchar(255),
@Designation nvarchar(255),
@SubDesignation nvarchar(255)


)
as

	set nocount on;

DECLARE @CHANGEAGENTID uniqueidentifier

	if @CHANGEAGENTID is null  
		exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output
				
	declare @CURRENTDATE datetime
	set @CURRENTDATE = getdate()


DECLARE @DesignationID uniqueidentifier
SET @DesignationID = (SELECT ID FROM DESIGNATION WHERE USERID = @Designation)
IF @DesignationID IS NULL BEGIN
  SET @DesignationID = (SELECT ID FROM DESIGNATION WHERE USERID = @SubDesignation)
END

IF @DesignationID IS NULL BEGIN
  RAISERROR('Could not get DESIGNATION for USERID', 16, 1)
END


	begin try
    
    UPDATE REVENUE 
    SET
    RECEIPTAMOUNT = @Amount,
    AMOUNT = @Amount,
    DESCRIPTION = @Description, 
    ORGANIZATIONAMOUNT = @Amount, 
    TRANSACTIONAMOUNT = @Amount, 
    CHANGEDBYID = @CHANGEAGENTID, 
    DATECHANGED = @CURRENTDATE
    WHERE ID = @ID

    UPDATE REVENUESPLIT
    SET 
    DESIGNATIONID = @DesignationID, 
    AMOUNT = @Amount, 
    DESCRIPTION = @Description, 
    ORGANIZATIONAMOUNT = @Amount, 
    TRANSACTIONAMOUNT = @Amount,
    CHANGEDBYID = @CHANGEAGENTID, 
    DATECHANGED = @CURRENTDATE
    WHERE REVENUEID = @ID


    UPDATE REVENUEPAYMENTMETHOD
    SET
    AMOUNT = @Amount, 
    CHANGEDBYID = @CHANGEAGENTID, 
    DATECHANGED = @CURRENTDATE
    WHERE REVENUEID = @ID




	end try
	begin catch
		exec dbo.USP_RAISE_ERROR
		return 1
	end catch

return 0;
				]]>
			</common:CreateProcedureSQL>
		</SaveImplementation>

	</SPDataForm>

	<!-- describe fields on the form, which correspond to parameters on the SP.  Note that system paramters 
	like the record ID, DATALOADED, TSLONG, and CURRENTAPPUSERID need not be listed. -->
	<common:FormMetaData FixedDialog="true">
		<common:FormFields>
      <common:FormField FieldID="Amount" Caption="Amount" DataType="Money" />
      <common:FormField FieldID="Description" Caption="Description" DataType="String" MaxLength="255" />
      <common:FormField FieldID="Designation" Caption="Designation" DataType="String" MaxLength="255" />
      <common:FormField FieldID="SubDesignation" Caption="SubDesignation" DataType="String" MaxLength="255" />

    </common:FormFields>

	</common:FormMetaData>

</EditDataFormTemplateSpec>